<?php
/**
 * File Name : HargaSewa.php
 * File Path : Application/Model/
 * Category  : Model
 * Created   : Senin, 5 Maret 2012 13:56
 * Author    : Bayu Santoso
 * Function  : To Manipulate 'tabel_harga_sewa'
 */

class Application_Model_HargaSewa extends Zend_Db_Table_Abstract
{
    protected $_name = 'tabel_harga_sewa';
    
    public function hargaSewaBaru($data)
    {
        $id = $this->insert($data);
        return $id;
    }
    
    public function hargaSewaUpdate($data, $id)
    {
        $this->update($data, 'id_harga_sewa = '.(int)$id);
    }
    
    public function hargasewaDelete($id)
    {
        $this->delete('daya_kva = '.(int)$id);
    }
    
    public function getAllData()
    {
        $result = $this->fetchAll();
        
        if($result)
        {
            return $result->toArray();
        } else {
            return false;
        }
    }
    
    public function getDataDaya()
    {
        $select = $this->select();
        $select->from($this->_name, 'daya_kva')
               ->columns('daya_kva')
               ->distinct(true);
        
        $result = $this->fetchAll($select);
        if($result)
        {
            return $result->toArray();
        } else {
            return false;
        }
    }
    
    public function getCount()
    {
        $result = $this->fetchAll();
        if($result)
        {
            return $result->count();
        } else {
            return false;
        }
    }
    
    public function getRow($daya_kva, $jenis_sewa)
    {
        $select = $this->select();
        $select->from($this->_name)
               ->where('daya_kva = ?', $daya_kva)
               ->where('jenis_sewa = ?', $jenis_sewa);
       
        $result = $this->fetchRow($select);
        if($result)
        {
            return $result->toArray();
        } else {
            return false;
        }
    }
    
    public function getHarga($daya_kva)
    {
        $select = $this->select();
        $select->from($this->_name)
               ->where('daya_kva = ?', $daya_kva);
       
        $result = $this->fetchAll($select);
        if($result)
        {
            return $result->toArray();
        } else {
            return false;
        }
    }
    
    public function checkHarga($daya_kva)
    {
        $select = $this->select();
        $select->from($this->_name)
               ->where('daya_kva = ?',$daya_kva)
               ->limit(2);
        
        $result = $this->fetchAll($select);
        
        if($result and ($result->count() <= 2 and $result->count() > 0))
        { return true;
        } else {
            return false;
        }
    }
}

